<?php

final class ArticlesQueries {
    private static $getArticle = "SELECT a.title, a.content, a.type, a.posted, a.edited, a.editedby, u.id as 'authourid', u.name as 'authour' FROM articles AS a LEFT JOIN users AS u ON u.id = a.postedby WHERE (a.id = ?)";
    private static $getEditedBy = 'SELECT id, name FROM users WHERE id = ?';

    private function __construct() {} // So the class can't be instantiated.
    
    public static function GetArticle($id) {
        $registry = Registry::GetInstance();
        $DB = $registry->Get('DB');
        $query = new pQuery(self::$getArticle);
        $DB->Query($query, 'a');
        $query->SetParams($id);
        $articles = $query->FetchResult();
        return $articles[0];
    }
    public static function GetEditedBy($id) {
        $registry = Registry::GetInstance();
        $DB = $registry->Get('DB');
        $query = new pQuery(self::$getEditedBy);
        $DB->Query($query);
        $query->SetParams($id);
        $edited = $query->FetchResult();
        return $edited[0];
    }
}